In [2]:
a = 24
b = 16
for i in range(min(a,b), 0, -1):
if a % i == 0 and b % i ==0:
print(i)
break
In [3]:
while b:
a,b=b,a%b
print(a)
In [4]:
print(max([x for x in range(1,a+1) if a%x==0 and b%x==0]))
In [11]:
for i in range(1, 10):
for j in range(1, i+1):
print ("%d x %d = %d" % (i, j, i*j),"\t",end="")
if i==j:
print("")
In [6]:
i=0
j=0
while i<9:
i+=1
while j<9:
j+=1
print(j,"x",i,"=",i*j,"\t",end="")
if i==j:
j=0
print("")
break
In [12]:
print('\n'.join(['\t'.join(["%2s x%2s = %2s"%(j,i,i*j) for j in range(1,i+1)]) for i in range(1,10)]))
In [5]:
def func1(a,b,c):
if (a+b)>c and (b+c)>a and (a+c)>b:
return 'yes'
else:
return 'no'
print(func1(1,2,3))
In [3]:
def func2(a,b,c):
if max(a,b,c)<(a+b+c)/2.0:
return 'yes'
else:
return 'no'
print(func2(3,4,5))
In [17]:
# 简单四则计算器代码,摘自 https://www.jianshu.com/p/c22bfd91df49
def calculate():
operation = input('''
please type in the math operation you would like to complete:
+ for addition
- for subtraction
* for multiplication
/ for division
''')
number_1 = float(input('Please enter the first number: '))
number_2 = float(input('Please enter the second number: '))
if operation == '+':
print('{} + {} = {} '.format(number_1, number_2,number_1 + number_2))
elif operation == '-':
print('{} - {} = {} '.format(number_1,number_2,number_1 - number_2))
elif operation == '*':
print('{} * {} = {} '.format(number_1, number_2,number_1 * number_2))
elif operation == '/' and number_2 != 0:
print('{} / {} = {} '.format(number_1, number_2,number_1 / number_2))
else:
print('You have not typed a valid operator, please run the program again.')
calculate()